/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
**/

package com.chasekernan.hxnova.componenteditor;

import com.chasekernan.hxnova.server.IO;
import haxe.remoting.Context;

class Base {
    static var window : swhx.Window;
    static var flash : swhx.Flash;
	static var context : Context;

    static function main() {
        swhx.Application.init();
        
        window = new swhx.Window("HxNova -- Component Editor", 800, 650);
        window.maximizeIcon = true;
        window.resizable = true;
        
		context = new Context();
		context.addObject("Base", Base);
        
        flash = new swhx.Flash(window, context);
        flash.setAttribute("src","ui.swf");
        flash.start();
        
        window.visible = true;
        swhx.Application.loop();
        swhx.Application.cleanup();
    }
    
    //TODO: Define entry point for component saving
    public static function save(c : String) {
		var fileLocation = systools.Dialogs.saveFile("Save Components", "Save", "C:\\");
		if (fileLocation == null) return;
        IO.writeToFile(IO.compress(c), fileLocation + ".hxnova-components");
    }
    
    //TODO: Disable multiple selection?
    public static function load() : String {
        var loc = systools.Dialogs.openFile("Load Components", "Load", { count : 1, descriptions : ["HxNova Component Set"], extensions : ["*.hxnova-components"] } );
        return IO.uncompress(IO.readFromFile(loc[0]));
    }
    
}